/* GUI CONVERTED from rcshwbd1.p (converter v1.76) Tue Aug 20 15:41:54 2002 */
/* rcshwbd1.p  - CONTAINER WORKBENCH - SUB PROGRAM - ADD EXISTING CONT     */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                     */
/* All rights reserved worldwide.  This is an unpublished work.            */
/* $Revision: 1.8.1.10 $                                                            */
/*V8:ConvertMode=Maintenance                                               */
/* VERSION 8.6            CREATED: 09/24/97   BY: *K0JC* John Worden       */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane       */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan      */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *J2RZ* Dana Tunstall   */
/* REVISION: 8.6E     LAST MODIFIED: 07/22/98   BY: *J2M7* Niranjan R.     */
/* REVISION: 8.6E     LAST MODIFIED: 08/18/99   BY: *K223* Santosh Rao     */
/* REVISION: 8.6E     LAST MODIFIED: 11/03/99   BY: *J3L5* Santosh Rao     */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane*/
/* REVISION: 9.1      LAST MODIFIED: 04/13/00   BY: *K250* Surekha Joshi   */
/* REVISION: 9.1      LAST MODIFIED: 07/24/00   BY: *N0GD* Ganga Subramanian */
/* Revision: 1.8.1.8  BY: Dan Herman   DATE: 07/09/01        ECO: *P007*   */
/* Revision: 1.8.1.9     BY: Rajaneesh S. DATE: 02/21/02        ECO: *L13N*   */
/* $Revision: 1.8.1.10 $  BY: Samir Bavkar    DATE: 08/15/02 ECO: *P09K*   */

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

{rcinvtbl.i new}  /* DEFINITIONS NEEDED FOR rcinvcon.i */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE rcshwbd1_p_1 "Volume"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcshwbd1_p_2 "Volume UM"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcshwbd1_p_3 "UM"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcshwbd1_p_4 "Ref"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcshwbd1_p_5 "Quantity"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcshwbd1_p_6 "Container Item"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcshwbd1_p_8 "Existing Container"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcshwbd1_p_9 "Multi Entry"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

/* INPUT PARAMETERS */
define input parameter ship_from as character no-undo.
define input parameter temp_parent as character no-undo.
define input parameter cont_level as integer no-undo.
define input parameter parent_number as character no-undo.
define input parameter tmp_prefix as character no-undo.
define input parameter p-abs_format like abs_mstr.abs_format no-undo.
define input parameter shipto_code as character no-undo.

/* LOCAL VARIABLES */
define variable num_containers as integer format ">>>9"
   label {&rcshwbd1_p_5} no-undo.
define variable beg_cont_num as character format "X(8)"
   label {&rcshwbd1_p_8} no-undo.
define variable container_item like pt_part
   label {&rcshwbd1_p_6} no-undo.
define variable cont_site like abs_site no-undo.
define variable item_description like pt_desc1 format "X(20)"
   no-undo.
define variable item_description_2 like pt_desc2 format "X(20)"
   no-undo.
define variable item_um as character format "XX" no-undo.
define variable cont_loc like abs_loc no-undo.
define variable cont_wght like pt_net_wt no-undo.
define variable cont_wt_um like pt_net_wt_um no-undo.
define variable cont_vol like pt_size
   label {&rcshwbd1_p_1} no-undo.
define variable cont_vol_um like pt_size_um
   label {&rcshwbd1_p_2} no-undo.
define variable multiple like mfc_logical
   label {&rcshwbd1_p_9} no-undo.
define variable undotran as logical no-undo.
define variable i as integer no-undo.
define variable cont_qty as integer no-undo.
define variable cont_lot_ser like abs_lot no-undo.
define variable cont_ref like abs_ref
   label {&rcshwbd1_p_4} no-undo.
define variable modulo_qty as integer no-undo.
define variable gwt_total like abs_gwt no-undo.
define variable vol_total like abs_vol no-undo.
define variable cont_qty_um like pt_um no-undo.
define variable error_flag as integer no-undo.
define variable ok_to_create as logical no-undo.
define variable old_nwt like abs_mstr.abs_nwt no-undo.
define new shared variable new_site as character.
define new shared variable so_db as character.
define new shared variable err_stat as integer.
define variable disp_abs_id like abs_mstr.abs_id no-undo.

/* SHARED VARIABLES TO CALL EXISTING CODE */
define new shared variable multi_entry as logical no-undo.
define new shared variable cline as character no-undo.
define new shared variable lotserial_control like pt_lot_ser no-undo.
define new shared variable issue_or_receipt as character

   initial "Issue" no-undo.
define new shared variable total_lotserial_qty like sr_qty no-undo.
define new shared variable site like sr_site no-undo.
define new shared variable location like sr_loc no-undo.
define new shared variable lotserial like sr_lotser no-undo.
define new shared variable lotserial_qty like sr_qty no-undo.
define new shared variable trans_um like pt_um no-undo.
define new shared variable trans_conv like sod_um_conv no-undo.
define new shared variable transtype as character
   initial "ISS-UNP" no-undo.
define new shared variable lotref like sr_ref no-undo.
define new shared temp-table work_sr_wkfl like sr_wkfl.
define variable msg1 as character format "x(28)" no-undo.

define variable sales_order like abs_order no-undo.
define variable order_line like abs_line no-undo.

define variable use-log-acctg as logical no-undo.
define variable l_FrTermsErr like mfc_logical no-undo.
define variable l_FrTermsOnFirstOrder like so_fr_terms no-undo.

/* BUFFERS */
define buffer parent_container for abs_mstr.
define buffer abs_temp for abs_mstr.

msg1 = getTermLabel("FOR_REMOTE_INVENTORY", 28).

/* FORM FOR ADD CONTAINERS */


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/  
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
beg_cont_num colon 25 skip(1)
   container_item colon 25
   item_description at 27 no-label
   item_description_2 at 27 no-label
   num_containers colon 25
   cont_site colon 58
   item_um colon 25 label {&rcshwbd1_p_3}
   cont_loc colon 58
   cont_lot_ser colon 58
   cont_wght colon 25
   cont_wt_um no-label
   cont_ref colon 58
   cont_vol colon 25
   cont_vol_um no-label
   multiple colon 58
   sales_order colon 25
   order_line colon 58
 SKIP(.4)  /*GUI*/
with frame a side-labels
   width 80  attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER.
 F-a-title = (getFrameTitle("CONTAINER_INFORMATION",30)).
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame a =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame a + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5. /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

/* INITIALIZE CENTRAL DATABASE ALIAS NAME */
so_db = global_db.

/* RESET STATUS */
status input.

/* CHECK IF LOGISTICS ACCOUNTING IS ENABLED */
{gprun.i ""lactrl.p"" "(output use-log-acctg)"}
/*GUI*/ if global-beam-me-up then undo, leave.


MAIN:
do:
   assign
      num_containers = 1
      beg_cont_num = "".

   display num_containers with frame a.

   GET_DATA:
   do on endkey undo GET_DATA, leave MAIN
         on error undo GET_DATA, retry GET_DATA:
/*GUI*/ if global-beam-me-up then undo, leave.


      /* GET CONTAINER NUMBER */
      update beg_cont_num with frame a
      editing:
         if frame-field = "beg_cont_num" then do:
            {mfnp05.i abs_mstr abs_id
               "(abs_shipfrom = ship_from and abs_id begins 'c' )"
               abs_id
               "('c' + input beg_cont_num)"}

            if recno <> ? then do:
               disp_abs_id = substring(abs_id,2,8).
               if available abs_mstr then do:
                  assign
                     cont_loc = abs_mstr.abs_loc
                     cont_qty_um = abs_mstr.abs__chr02
                     cont_site = abs_mstr.abs_shipfrom
                     cont_wght = abs_mstr.abs_nwt
                     cont_wt_um = abs_mstr.abs_wt_um
                     cont_vol = abs_mstr.abs_vol
                     cont_vol_um = abs_mstr.abs_vol_um
                     multiple = false
                     lotserial_control = abs_mstr.abs_lot
                     sales_order = abs_mstr.abs_order
                     order_line = abs_mstr.abs_line
                     container_item = abs_mstr.abs_item.
                  find first pt_mstr where pt_part = container_item
                     no-lock no-error.
                  if available pt_mstr then
                  display
                     pt_part @ container_item
                     pt_desc1 @ item_description
                     pt_desc2 @ item_description_2
                     pt_um @ item_um
                     cont_site
                     cont_loc
                     cont_lot_ser
                     cont_ref
                     cont_wght
                     cont_wt_um
                     cont_vol
                     cont_vol_um
                     multiple
                     sales_order
                     order_line
                  with frame a.
               end. /* available abs_mstr */
               display
                  disp_abs_id @ beg_cont_num
               with frame a.
            end. /* if recno <> ? */
         end. /* if field = beg_cont_num */
         else do:
            status input.
            readkey.
            apply lastkey.
         end. /* else do */
      end. /* editing */

      find abs_mstr where abs_shipfrom = ship_from
         and abs_mstr.abs_id = "c" + beg_cont_num
         no-lock no-error.

      if not available abs_mstr then do:
         {pxmsg.i &MSGNUM=763 &ERRORLEVEL=3} /* container id does not exist */
         undo get_data, retry get_data.
      end. /* not available abs_mstr */

      disp_abs_id = substring(abs_id,2,8).
      if available abs_mstr then do:
         assign
            cont_loc = abs_mstr.abs_loc
            cont_qty_um = abs_mstr.abs__chr02
            cont_site = abs_mstr.abs_shipfrom
            cont_wght = abs_mstr.abs_nwt
            cont_wt_um = abs_mstr.abs_wt_um
            cont_vol = abs_mstr.abs_vol
            cont_vol_um = abs_mstr.abs_vol_um
            multiple = false
            lotserial_control = abs_mstr.abs_lot
            sales_order = abs_mstr.abs_order
            order_line = abs_mstr.abs_line
            container_item = abs_mstr.abs_item.
         find first pt_mstr where pt_part = container_item
            no-lock no-error.
         if available pt_mstr then
         display
            pt_part @ container_item
            pt_desc1 @ item_description
            pt_desc2 @ item_description_2
            pt_um @ item_um
            cont_site
            cont_loc
            cont_lot_ser
            cont_ref
            cont_wght
            cont_wt_um
            cont_vol
            cont_vol_um
            multiple
            sales_order
            order_line
         with frame a.
      end. /* if availabel abs_mstr */

      /* VALIDATE THAT THIS CONTAINER IS NOT ASSIGNED TO ANYONE */
      if abs_mstr.abs_par_id <> "" then do:
         {pxmsg.i &MSGNUM = 8223 &ERRORLEVEL = 3
                  &MSGARG1 = substring(abs_mstr.abs_par_id,2)}
         /*Container is on shipper */
         undo get_data, retry get_data.
      end. /* abs_mtr.abs_par_id <> "" */

      /* VALIDATE THAT THE SHIPTO OF THE CONTAINER
      IS THAT OF THE PRESHIPPER */
      if abs_mstr.abs_shipto <> "" then do:

         /* FIND SHIPPER MASTER RECORD USING SHIP-FROM ID AND ID */
         /* TO IMPROVE PERFORMANCE                               */
         for first parent_container
               fields(abs_dataset abs_gwt abs_id abs_item abs_line abs_loc
               abs_lotser abs_nwt abs_order abs_par_id abs_ref
               abs_shipfrom abs_shipto abs_shp_date abs_site
               abs_type abs_vol abs_vol_um abs_wt_um abs__chr02
               abs__qad06)
               where parent_container.abs_shipfrom = ship_from     and
               parent_container.abs_id       = parent_number
               no-lock:
         end. /* FOR FIRST PARENT_CONTAINER */

         if available parent_container
            and parent_container.abs_shipto <> abs_mstr.abs_shipto
         then do:
            {pxmsg.i &MSGNUM=8224 &ERRORLEVEL=3}
            /* Container ID assigend to different ship-to */
            undo get_data, retry get_data.
         end. /* if available parent_container */
      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* if abs_shipto <> "" */

      /* VALIDATE THE PART OF THE CONTAINER */
      SET_DATA:
      do on endkey undo GET_DATA, retry GET_DATA
            on error undo SET_DATA, retry SET_DATA:
/*GUI*/ if global-beam-me-up then undo, leave.


         assign
            new_site = ship_from
            global_part = container_item.

         /* VALIDATE THAT PART EXISTS AT THE SITE */
         {gprun.i ""gpptsi01.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


         if err_stat = 2 then do:
            {pxmsg.i &MSGNUM=16 &ERRORLEVEL=3} /* PART NOT FOUND */
            next-prompt container_item with frame a.
            undo SET_DATA, retry SET_DATA.
         end. /* err_stat = 2 */
      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* SET_DATA */

      find pt_mstr where pt_part = container_item no-lock no-error.

      display pt_desc1 when (available pt_mstr) @ item_description
         pt_desc2 when (available pt_mstr) @ item_description_2
         pt_um when (available pt_mstr) @ item_um
      with frame a.

      display
         cont_site
         cont_loc
         cont_lot_ser
         cont_ref
         cont_wght
         cont_wt_um
         cont_vol
         cont_vol_um
         multiple
         sales_order
         order_line
      with frame a.

      /* GET INVENTORY DETAIL INFORMATION */
      INV_DETAIL:
      do on endkey undo GET_DATA, retry GET_DATA
            on error undo INV_DETAIL, retry INV_DETAIL:
/*GUI*/ if global-beam-me-up then undo, leave.


         if num_containers = 0 then do:
            {pxmsg.i &MSGNUM=317 &ERRORLEVEL=3} /* CANNOT BE ZERO */
            undo INV_DETAIL, retry INV_DETAIL.
         end. /* num_containers = 0 */

         /* DELETE OLD SR_WKFL RECORDS */
         for each sr_wkfl where sr_userid = mfguser exclusive-lock:
            delete sr_wkfl.
         end. /* for each sr_wkfl */

         for each lotw_wkfl
            where lotw_mfguser = mfguser
            exclusive-lock:
            delete lotw_wkfl.
         end. /* FOR EACH lotw_wkfl */


         /* SWITCH TO THE REMOTE SITE IF NECESSARY */
         {gprun.i ""gpalias2.p""
            "(input cont_site,
                      output error_flag)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         if error_flag <> 0 and error_flag <> 9 then do:
            /* UNABLE TO CONNECT TO REMOTE DATABASE */
            {pxmsg.i &MSGNUM = 2510 &ERRORLEVEL = 4 &MSGARG1 = msg1}

            undo INV_DETAIL, retry INV_DETAIL.
         end.

         do:
            /* VALIDATE THE INVENTORY DETAIL INFORMATION */
            /* ADDED UM CONV AS TENTH INPUT PARAMETER ; PASSING ZERO  */
            {gprun.i ""rcctmtb.p"" "(input transtype,
                               input ship_from,
                               input cont_site,
                               input cont_loc,
                               input container_item,
                               input cont_lot_ser,
                               input cont_ref,
                               input num_containers,
                               input cont_qty_um,
                               input 0,
                               output undotran)"}
/*GUI*/ if global-beam-me-up then undo, leave.

            if undotran then do:
               /* RESET TO CENTRAL DATABASE IF NECESSARY */
               {gprun.i ""gpalias3.p""
                  "(input so_db,
                          output error_flag)"}
/*GUI*/ if global-beam-me-up then undo, leave.

               undo INV_DETAIL, retry INV_DETAIL.
            end. /* if undotran */
         end. /* do */
         /* SET WORK_SR_WKFL WORKFILE RECORDS */
         {gprun.i ""rcshmtb2.p""
            "(input mfguser, input cline)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         /* RESET TO CENTRAL DATABASE IF NECESSARY */
         {gprun.i ""gpalias3.p""
            "(input so_db,
                      output error_flag)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* INV_DETAIL */

      run val_sales_orders
         (input abs_mstr.abs_id,
         input ship_from,
         input shipto_code,
         output ok_to_create).
      if not ok_to_create then undo get_data, retry get_data.

      if use-log-acctg then do:
         /* VALIDATE SALES ORDER FREIGHT TERMS FOR THIS CONTAINER/SHIPPER */
         run validateSOFrTerms (input abs_mstr.abs_id, /* CONTAINER ID */
                                input parent_number,
                                input ship_from,
                                output l_FrTermsOnFirstOrder,
                                output l_FrTermsErr).
         if l_FrTermsErr then do:
            /* ALL ATTACHED ORDERS MUST HAVE FREIGHT TERMS # */
            {pxmsg.i &MSGNUM=5056 &ERRORLEVEL=3 &MSGARG1=l_FrTermsOnFirstOrder}
            undo get_data, retry get_data.
         end. /* IF l_FrTermsErr */
      end.   /* if use-log-acctg */
   end. /* GET_DATA */

   do transaction:
      /* CREATE WORK_SR_WKFL FOR NOT MULTI-ENTRY */
      find first work_sr_wkfl where work_sr_wkfl.sr_userid = mfguser
         no-lock no-error.
      if not available work_sr_wkfl then do:
         create work_sr_wkfl.

         assign
            work_sr_wkfl.sr_userid = mfguser
            work_sr_wkfl.sr_site = cont_site
            work_sr_wkfl.sr_loc = cont_loc
            work_sr_wkfl.sr_lotser = cont_lot_ser
            work_sr_wkfl.sr_ref = cont_ref
            work_sr_wkfl.sr_qty = num_containers.
      end. /* not available work_sr_wkfl */
   end. /* DO TRANSACTION */

   num_containers = 0.

   ASSIGN_CONTAINERS:
   do for mfc_ctrl transaction:
/*GUI*/ if global-beam-me-up then undo, leave.


      /* ASSIGN THE ALLOTED NUMBER OF CONTAINER RECORDS */
      /* FROM THE SR_WKFL RECORDS */
      for each work_sr_wkfl where work_sr_wkfl.sr_userid = mfguser
            exclusive-lock:
/*GUI*/ if global-beam-me-up then undo, leave.


         do i = 1 to work_sr_wkfl.sr_qty:
            find abs_mstr where abs_mstr.abs_shipfrom = ship_from
               and abs_mstr.abs_id = "c" + beg_cont_num
               exclusive-lock no-error.

            assign
               abs_mstr.abs_par_id   = parent_number
               abs_mstr.abs_shp_date = today
               abs_mstr.abs_type     = "s"
               abs_mstr.abs__qad06   = string(cont_level,"99")
               abs_mstr.abs_ref      = cont_ref
               abs_mstr.abs_site     = cont_site.

            find first parent_container
               where parent_container.abs_shipfrom = ship_from
               and parent_container.abs_id = parent_number
               exclusive-lock no-error.
            if available parent_container then do:
               assign old_nwt = parent_container.abs_nwt.
               /* ADDED 3RD PARAMETER, CHANGE_NET; PASSING NO TO IT */

               /* CHANGED SECOND INPUT PARAMETER FROM ABS_MSTR.ABS_GWT */
               /* TO ABS_MSTR.ABS_NWT, THIRD INPUT PARAMETER FROM NO   */
               /* TO YES                                               */
               {gprun.i ""icshnwt.p""
                  "(input recid(parent_container),
                               input abs_mstr.abs_nwt,
                               input yes,
                               input abs_mstr.abs_wt_um)"}
/*GUI*/ if global-beam-me-up then undo, leave.


               /* ROLLUP TARE WEIGHT */
               {gprun.i ""icshnwt.p""
                  "(input recid(parent_container),
                               input (abs_mstr.abs_gwt - abs_mstr.abs_nwt),
                               input no,
                               input abs_mstr.abs_wt_um)"}
/*GUI*/ if global-beam-me-up then undo, leave.

            end. /* available parent_container */
            assign
               num_containers = num_containers + 1
               beg_cont_num = "".
         end. /* DO I = 1 TO SR_QTY */

         delete work_sr_wkfl.

      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* FOR EACH SR_WKFL */

      i = 0.

      /* COUNT THE NUMBER OF CHILD CONTAINERS THAT NEED TO BE       */
      /* ASSIGNED TO THIS PARENT LEVEL AND SAVE IN i                */
      for each abs_mstr where abs_mstr.abs_shipfrom = ship_from
            and abs_mstr.abs_shipto = temp_parent
            and integer(abs_mstr.abs__qad06) = cont_level - 1 no-lock:
         i = i + 1.
      end. /* for each abs_mstr ... */

      /* QTY TO ASSIGN TO EACH PARENT */
      assign
         cont_qty = (i - (i modulo num_containers)) / num_containers
         modulo_qty = i modulo num_containers.

      find first parent_container
         where parent_container.abs_shipfrom = ship_from
         and parent_container.abs_shipto = temp_parent
         and integer(parent_container.abs__qad06) = cont_level
         exclusive-lock no-error.

      /* CHILD CONTAINER */
      find first abs_mstr where abs_mstr.abs_shipfrom = ship_from
         and abs_mstr.abs_shipto = temp_parent
         and integer(abs_mstr.abs__qad06) = (cont_level - 1)
         exclusive-lock no-error.

      /* ASSIGN CHILD CONTAINERS TO PARENT CONTAINERS */
      ASSIGN_CHILD:
      repeat while available parent_container and available abs_mstr:
         /* ASSIGN i THE NUMBER OF CHILD RECORDS TO ASSIGN */
         i = cont_qty.

         /* ASSIGN i NUMBER OF CHILD CONTAINERS TO THIS PARENT */
         do while i > 0 or modulo_qty > 0:
            if available abs_mstr then do:
               /* PLACE MODULO ON FIRST RECORD ONLY */
               if modulo_qty > 0 then modulo_qty = modulo_qty - 1.
               else i = i - 1.

               /* ASSIGN THE PARENT ID TO THE RECORD */
               abs_mstr.abs_par_id = parent_container.abs_id.
            end. /* IF AVAILABLE ABS_MSTR */
            else leave ASSIGN_CHILD.

            find next abs_mstr where abs_mstr.abs_shipfrom = ship_from
               and abs_mstr.abs_shipto = temp_parent
               and integer(abs_mstr.abs__qad06) = (cont_level - 1)
               exclusive-lock no-error.
         end. /* do while i > 0 or ... */

         /* ADD WEIGHTS OF CHILD RECORDS */
         for each abs_temp
               where abs_temp.abs_shipfrom = parent_container.abs_shipfrom
               and abs_temp.abs_par_id = parent_container.abs_id
               no-lock:
            gwt_total = gwt_total + abs_gwt.
         end. /* for each abs_temp */

         parent_container.abs_gwt = parent_container.abs_nwt +
         gwt_total.

         find next parent_container
            where parent_container.abs_shipfrom = ship_from
            and parent_container.abs_shipto = temp_parent
            and integer(parent_container.abs__qad06) = cont_level
            exclusive-lock no-error.
      end. /* assign_child */
   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* ASSIGN_CONTAINERS */
end. /* MAIN */
hide frame a no-pause.

PROCEDURE val_sales_orders:
   define input parameter absid like abs_mstr.abs_id no-undo.
   define input parameter shipfrom like abs_mstr.abs_shipfrom no-undo.
   define input parameter shipto like abs_mstr.abs_shipto no-undo.

   define output parameter p-passed as logical no-undo.

   define buffer abs_buff for abs_mstr.
   define buffer abs_parent for abs_mstr.

   p-passed = yes.

   /* FIND SHIPPER MASTER RECORD USING SHIP-FROM ID AND ID */
   /* TO IMPROVE PERFORMANCE                               */
   for first abs_parent
         fields(abs_dataset abs_gwt abs_id abs_item abs_line abs_loc
         abs_lotser abs_nwt abs_order abs_par_id abs_ref
         abs_shipfrom abs_shipto abs_shp_date abs_site
         abs_type abs_vol abs_vol_um abs_wt_um abs__chr02
         abs__qad06)
         where abs_parent.abs_shipfrom = shipfrom and
         abs_parent.abs_id       = absid no-lock:
   end. /* FOR FIRST ABS_PARENT */

   do-loop:
   do for abs_buff:
      for each abs_buff
            where abs_shipfrom = shipfrom
            and abs_par_id = absid
            no-lock
            break
            by abs_shipfrom
            by abs_dataset
            by abs_order:
/*GUI*/ if global-beam-me-up then undo, leave.

         if first-of(abs_order) then do:
            if abs_order <> "" then
            {gprun.i ""rcshsov.p""
               "(input recid(abs_buff),
                     input recid(abs_parent),
                     input p-abs_format,
                     input abs_buff.abs_order,
                     input abs_buff.abs_line,
                     input shipto,
                     output p-passed)"
               }
/*GUI*/ if global-beam-me-up then undo, leave.

            else
               if abs_buff.abs_id begins "i" then do:
               {pxmsg.i &MSGNUM=8285 &ERRORLEVEL=2}
               /* BLANK NOT ALLOWED */
               next.
            end.
            if not p-passed then leave do-loop.
         end.
         run val_sales_orders
            (input abs_id,
            input abs_shipfrom,
            input shipto,
            output p-passed).
         if not p-passed then leave do-loop.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* for each abs_buff */
   end. /* do for abs_buff */
END PROCEDURE. /* val_sales_orders */

{rcinvcon.i}   /* INTERNAL PROCEDURE get_abs_parent INCLUDED IN THIS .i */

PROCEDURE validateSOFrTerms:
/*--------------------------------------------------------------------
   Purpose:     Get the highest level parent (Shipper/Pre-Shipper record)
                Get the freight terms on the first order attached to the
                  Shipper/Pre-Shipper record.
                Get the freight terms on the first order attached to the
                  container.
                Compare the two freight terms and return op_FrTermsErr
                  if they are different.
   Parameters:
   Notes:
----------------------------------------------------------------------*/
   define input parameter ip_AbsId    like   abs_id       no-undo.
   define input parameter ip_ParentAbsId  like   abs_id       no-undo.
   define input parameter ip_ShipFrom     like   abs_shipfrom no-undo.

   define output parameter op_FrTermsOnFirstOrder as character  no-undo.
   define output parameter op_FrTermsErr like mfc_logical  no-undo.

   define buffer abs_buff1 for abs_mstr.
   define buffer abs_buff2 for abs_mstr.
   define buffer abs_buff3 for abs_mstr.

   define variable par_absid like abs_id no-undo.
   define variable par_shipfrom like abs_shipfrom no-undo.
   define variable l_FirstOrderOnShip like so_nbr no-undo.
   define variable l_FirstOrderOnCont like so_nbr no-undo.
   define variable l_FrTermsOnFirstOrderOnShip as character  no-undo.
   define variable l_FrTermsOnFirstOrderOnCont as character  no-undo.

   /* MAKE SURE THAT THE PARENT_ID IS ACTUALLY THE HIGHEST LEVEL PARENT */
   /* THIS CONTAINER (I.E. IT IS A SHIPPER/PRE-SHIPPER )                */
   for first abs_buff1 where abs_buff1.abs_id = ip_ParentAbsId  and
      abs_buff1.abs_shipfrom = ip_ShipFrom
      no-lock:
   end.
   if available abs_buff1 and
      abs_buff1.abs_par_id = "" and
      (abs_buff1.abs_id begins "p" or
       abs_buff1.abs_id begins "s") then
     assign
       par_absid = ip_ParentAbsId
       par_shipfrom = ip_ShipFrom.
   else do:
     run get_abs_parent (input ip_AbsId,
                         input ip_ShipFrom,
                         output par_absid,
                         output par_shipfrom).
   end. /* ELSE, NOT AVAILABLE abs_buff1 */

   if par_absid <> ? then
   do for abs_buff2:
      for first abs_buff2 where abs_buff2.abs_id = par_absid and
         abs_buff2.abs_shipfrom = par_shipfrom
         no-lock:
      end.
      if available abs_buff2 then do:
         {gprunmo.i  &module = "LA" &program = "lashex01.p"
                     &param  = """(buffer abs_buff2,
                                   output l_FirstOrderOnShip,
                                   output l_FrTermsOnFirstOrderOnShip)"""}

      end. /* IF AVAILABLE abs_buff2 */
   end. /* DO FOR ABS_BUFF2 */

  /* IF FIRST ORDER ON SHIPPER IS BLANK THAT MEANS THERE IS NO ORDER ATTACHED */
  /* SO NO FREIGHT TERMS TO VALIDATE AGAINST.                                 */

  if l_FirstOrderOnShip <> "" then do:
     /* GET THE CONTAINER RECORD */
     for first abs_buff3 where abs_buff3.abs_id = ip_AbsId  and
        abs_buff3.abs_shipfrom = ip_ShipFrom
        no-lock:
     end.
     if available abs_buff3 then do:
        {gprunmo.i  &module = "LA" &program = "lashex01.p"
                    &param  = """(buffer abs_buff3,
                                  output l_FirstOrderOnCont,
                                  output l_FrTermsOnFirstOrderOnCont)"""}

     end. /* IF AVAILABLE abs_buff3 */

     if l_FirstOrderOnCont <> ""  and
        (l_FrTermsOnFirstOrderOnShip <> l_FrTermsOnFirstOrderOnCont) then do:
        assign
           op_FrTermsErr = true.
           op_FrTermsOnFirstOrder = l_FrTermsOnFirstOrderOnShip.
        return.
     end. /* IF l_FirstOrderOnCont <> "" .... */
  end. /* IF l_FirstOrderOnShip.... */

END PROCEDURE. /* validateSOFrTerms */
